package org.ykh.gmall.product.controller;

import org.ykh.gmall.product.BaseTrademark;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.ykh.gmall.product.service.BaseTrademarkService;
import org.ykh.gmall.result.Result;

@RestController
@RequestMapping("/admin/product/baseTrademark")
public class BaseTrademarkController {


    @Autowired
    private BaseTrademarkService baseTrademarkService;



    /**
     * /admin/product/baseTrademark/get/{id}
     * 根据id回显
     * @param id
     * @return
     */
    @GetMapping("/get/{id}")
    public Result findById(@PathVariable Long id ){

        return  Result.ok(baseTrademarkService.getById(id));
    }


    /**
     * 修改保存/
     * /admin/product/baseTrademark/update
     * @param baseTrademark
     * @return
     */
    @PutMapping("/update")
    public Result update(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.updateById(baseTrademark);
        return Result.ok();

    }


    /**
     * admin/product/baseTrademark/save
     * 新增保存
     * @param baseTrademark
     * @return
     */
    @PostMapping("/save")
    public Result saveBasetraderMark(@RequestBody BaseTrademark baseTrademark){

        baseTrademarkService.save(baseTrademark);

        return Result.ok();
    }


    /**
     * /admin/product/baseTrademark/remove/{id}
     * 删除品牌
     * @param id
     * @return
     */
    @DeleteMapping("/remove/{id}")
    public Result removeTraderMark(@PathVariable Long id ){

        baseTrademarkService.removeById(id);

        return Result.ok();
    }


    /**
     * 品牌分页列表查询
     * admin/product/baseTrademark/{page}/{limit}
     * @param page
     * @param limit
     * @return
     */
    @GetMapping("/{page}/{limit}")
    public Result findBaseTradeMarkListByPage(@PathVariable Long page,
                                              @PathVariable Long limit){

        //封装分页条件对象
        Page<BaseTrademark> baseTrademarkPag=new Page<>(page,limit);
        IPage<BaseTrademark> baseTrademarkIPage = baseTrademarkService.page(baseTrademarkPag);

        return Result.ok(baseTrademarkIPage);
    }
}
